* {
    margin: 0;
    padding: 0;
    font-family: "Source Code Pro";
    box-sizing: border-box;
}

body {
    height: 100vh;
    background: linear-gradient(45deg,#99f,#f99);
}

body, .navbar, .navbar ul {
    display: flex;
    justify-content: center;
    align-items: center;
}

.navbar {
    position: relative;
    padding: 20px;
    border-radius: 50px;
    background-color: #fff;
}

.navbar input {
    width: 40px;
    height: 40px;
    cursor: pointer;
    opacity: 0;
}

.navbar span {
    position: absolute;
    left: 25px;
    top: calc(50% - 10px);
    width: 30px;
    height: 4px;
    border-radius: 15px;
    /* 两条线放在一起，利用 calc 错开位置 */
    background-color: #f99;
    pointer-events: none;
    transition: transform 0.3s ease-in-out, top .3s ease-in-out 0.3s;
}

.navbar span:nth-child(3) {
    /* 单独设置第二条线 */
    top: calc(50% + 6px);
}

.navbar ul {
    width: 0;
    white-space: nowrap;
    overflow: hidden;
    transition: all 0.5s ease;
}

.navbar ul li {
    list-style: none;
    margin: 0 15px;
}
.navbar ul li a {
    text-decoration: none;
    font-size: 20px;
    font-weight: 700;
    color: #333;
}

.navbar ul li a:hover {
    color: #fb7299;
}

.navbar input:checked ~ ul {
    width: 350px;
}

.navbar input:checked ~ span:nth-child(2) {
    top: calc(50% - 2px);
    transform: rotate(-45deg);
    background-color: #fb7299;
    transition: top .3s ease-in-out, transform 0.3s ease-in-out 0.3s;
}

.navbar input:checked ~ span:nth-child(3) {
    top: calc(50% - 2px);
    transform: rotate(45deg);
    background-color: #fb7299;
    transition: top .3s ease-in-out, transform 0.3s ease-in-out 0.3s;
}
